
<?php

require_once 'config/config.php';

class connect_db {

    static $db_connect;

    public function connect() {
        if (!isset(self::$db_connect)) {
            self::$db_connect = mysql_connect(DB_HOST . ":" . DB_PORT, DB_USER, DB_PASS) or die(mysql_error());
            mysql_select_db(DB_NAME, self::$db_connect);
            mysql_query('SET NAMES utf8', self::$db_connect);
        }
        return self::$db_connect;
    }

    public function query($query) {
        $data = mysql_query($query, self::$db_connect);
        $rows = array();
        while ($row = mysql_fetch_assoc($data)) {
            $rows[] = $row;
        }
        return $rows;
    }

}